package com.example.sqlitedemo.dao.util;

import com.example.sqlitedemo.MyApplication;
import com.example.sqlitedemo.dao.DaoManager;
import com.example.sqlitedemo.dao.entity.FaceFeature;
import com.example.sqlitedemo.dao.entity.ShootPhoto;
import com.example.sqlitedemo.greendao.FaceFeatureDao;
import com.example.sqlitedemo.greendao.ShootPhotoDao;
import com.example.sqlitedemo.util.DebugLog;

import org.greenrobot.greendao.query.QueryBuilder;
import org.greenrobot.greendao.query.WhereCondition;

import java.util.List;

/**
 * Created Date 2019/2/16.
 *
 * @author liangkun
 * ClassDescription：照片工具类
 */
public class PhotoDaoUtil {
    /**
     * 获取dao
     *
     * @return
     */
    public static ShootPhotoDao getPhotoDao() {
        return DaoManager.getInstance(MyApplication.getContext()).getDaoSession().getShootPhotoDao();
    }

    public static void getFaceList() {
        List<ShootPhoto> shootPhotos = getPhotoDao().loadAll();
        for (int i = 0; i < shootPhotos.size(); i++) {
            ShootPhoto shootPhoto = shootPhotos.get(i);
            //TODO:这个方法通过关联表
            List<FaceFeature> faceList = shootPhoto.getFaceList();
            for (int j = 0; j < faceList.size(); j++) {
                DebugLog.d(DebugLog.LOG+"照片MD5  "+shootPhoto.getPhotoMd5()+" 人脸tonken "+faceList.get(j).getFaceTonken()
                        +" 人脸对应照片的md5 "+faceList.get(j).getFaceMd5());
            }


            //TODO:这个方法不通过关联表，字段连接 查询该照片MD5下的所有人脸
//            QueryBuilder<FaceFeature> builder = FaceDaoUtil.getFaceDao().queryBuilder();
//            List<FaceFeature> picBeans = builder.where(FaceFeatureDao.Properties.FaceMd5.eq(shootPhoto.getPhotoMd5())).list();
////            for (int j = 0; j < picBeans.size(); j++) {
////                DebugLog.d(DebugLog.LOG + "照片MD5  " + shootPhoto.getPhotoMd5() + " 人脸tonken " + picBeans.get(j).getFaceTonken()
////                        + " 人脸对应照片的md5 " + picBeans.get(j).getFaceMd5());
////            }
        }
    }
}
